/*************************************************************************
 *
 *  elksip - a multi-platform Sip Phone Server
 *
 *  file: random.c
 *
 *  Copyright 2011-2013 Elksip team.
 *
 ************************************************************************/
#include <stdlib.h>
#include <time.h>
#define RANDOM_SIZE 100
//length<100
char* elk_generate_random_str(int length)
{  
    static int intr=0;
    static char rstr[RANDOM_SIZE+1];
    if(intr==0)
    {
        intr++;
#ifdef WIN32
        srand(_time32(0));
#else
        srand(time(NULL));
#endif
    }
    if(length > RANDOM_SIZE)
    {
        length = RANDOM_SIZE;
    }
    int r;
    int i;  
    for(i=0; i<length; i++) 
    {       
        r = rand() % ('z'- 'A') + 'A';
        if(r>'Z' && r< 'a')       
            r= '0'+ (r- 'Z');       
        rstr[i] = r;  
    } 
    rstr[length]= '\0';
    return rstr;
}

